local skel = fk.CreateSkill {
  name = "emo__wuxingsj",
}

Fk:loadTranslationTable{
  ["emo__wuxingsj"] = "五星上将",
  [":emo__wuxingsj"] = "每回合限一次，你受到伤害后，可以重置“避他锋芒”或弃置两张牌，然后回复1点体力。",

  ["#emo__wuxingsj-discard"] = "五星上将：你可以弃置两张牌，回复1点体力",
  ["#emo__wuxingsj-ask"] = "五星上将：可以重置“避他锋芒”或弃置两张牌，回复1点体力",
  ["emo__wuxingsj_reset"] = "重置“避他锋芒”",
  ["emo__wuxingsj_discard"] = "弃置两张牌",

  ["$emo__wuxingsj1"] = "如果上帝让我向他开枪，那么我会将枪口转向上帝",
  ["$emo__wuxingsj2"] = "当我在战场上看到他时，我就知道撤退已经来不及了",
}

skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player:usedSkillTimes(skel.name) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local cards = {}
    local skill = "emo__bitafm"
    -- 重置技能需要发动过，或者修改过描述
    if table.contains(player:getSkillNameList(), skill)
     and (player:usedSkillTimes(skill, Player.HistoryPhase) > 0 or player:getMark("emo__bitafm_change") ~= 0) then
      local choices = { "emo__wuxingsj_reset", "emo__wuxingsj_discard", "Cancel" }
      local choice = room:askToChoice(player, {
        choices = choices, skill_name = skel.name, prompt = "#emo__wuxingsj-ask"
      })
      if choice == "Cancel" then return false end
      if choice == "emo__wuxingsj_reset" then
        event:setCostData(self, { cards = cards })
        return true
      end
    end
    cards = room:askToDiscard(player, {
      min_num = 2, max_num = 2, include_equip = true, cancelable = true, skill_name = skel.name, skip = true,
      prompt = "#emo__wuxingsj-discard"
    })
    if #cards == 0 then return false end
    event:setCostData(self, { cards = cards })
    return true
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards or {}
    if #cards == 0 then
      player:clearSkillHistory("emo__bitafm")
      room:setPlayerMark(player, "emo__bitafm_change", 0)
    else
      room:throwCard(cards, skel.name, player, player)
    end
    if not player.dead then
      room:recover { num = 1, skillName = skel.name, who = player, recoverBy = player }
    end
  end,
})

return skel
